package fun.coding.leetcode;

public class PathSum {

	/**
	 *    1
	 *   2     and sum is 1 will return false, it has to be root to leaf, 1 is not a leaf, leaf has to be 
	 *   left and right == null
	 *   
	 *   if only root 1, it is root and also leaf
	 */
	public static void main(String[] args) {

	}

    public boolean hasPathSum(TreeNode root, int sum) {
    	return helper(root, sum, 0);
    }
    
    public boolean helper(TreeNode root, int sum, int cur) {
    	if (root == null) return false;
    	int newCur = cur + root.val;
    	if (root.left == null && root.right == null) return sum == newCur;
    	
    	
    	return helper(root.left, sum, newCur) || helper(root.right, sum, newCur);
    }
}
